package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DonationNeed;
import com.ruoyi.system.service.IDonationNeedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资需求Controller
 * 
 * @author ruoyi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/system/need")
public class DonationNeedController extends BaseController
{
    @Autowired
    private IDonationNeedService donationNeedService;

    /**
     * 查询物资需求列表
     */
    @PreAuthorize("@ss.hasPermi('system:need:list')")
    @GetMapping("/list")
    public TableDataInfo list(DonationNeed donationNeed)
    {
        startPage();
        List<DonationNeed> list = donationNeedService.selectDonationNeedList(donationNeed);
        return getDataTable(list);
    }

    /**
     * 导出物资需求列表
     */
    @PreAuthorize("@ss.hasPermi('system:need:export')")
    @Log(title = "物资需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DonationNeed donationNeed)
    {
        List<DonationNeed> list = donationNeedService.selectDonationNeedList(donationNeed);
        ExcelUtil<DonationNeed> util = new ExcelUtil<DonationNeed>(DonationNeed.class);
        util.exportExcel(response, list, "物资需求数据");
    }

    /**
     * 获取物资需求详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:need:query')")
    @GetMapping(value = "/{needId}")
    public AjaxResult getInfo(@PathVariable("needId") Long needId)
    {
        return success(donationNeedService.selectDonationNeedByNeedId(needId));
    }

    /**
     * 新增物资需求
     */
    @PreAuthorize("@ss.hasPermi('system:need:add')")
    @Log(title = "物资需求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DonationNeed donationNeed)
    {
        return toAjax(donationNeedService.insertDonationNeed(donationNeed));
    }

    /**
     * 修改物资需求
     */
    @PreAuthorize("@ss.hasPermi('system:need:edit')")
    @Log(title = "物资需求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DonationNeed donationNeed)
    {
        return toAjax(donationNeedService.updateDonationNeed(donationNeed));
    }

    /**
     * 删除物资需求
     */
    @PreAuthorize("@ss.hasPermi('system:need:remove')")
    @Log(title = "物资需求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{needIds}")
    public AjaxResult remove(@PathVariable Long[] needIds)
    {
        return toAjax(donationNeedService.deleteDonationNeedByNeedIds(needIds));
    }
}
